const app = getApp()
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    elements: [{
      title: '营业统计',
      name: 'Turnover ',
      color: 'cyan',
      icon: 'newsfill',
      bindtap:'goyingye'
    },
    {
      title: '菜品统计',
      name: 'Goods',
      color: 'blue',
      icon: 'colorlens',
      bindtap:'gogoods'
    },
    {
      title: '商铺订单查询',
      name: 'Inquire',
      color: 'purple',
      icon: 'font',
      bindtap:'golookdindan'
    },
    {
      title: '平台下单查询 ',
      name: 'Platform',
      color: 'mauve',
      icon: 'icon',
      bindtap:'golookpintaidindan'
    },
    {
      title: '订单搜索',
      name: 'Search',
      color: 'pink',
      icon: 'btn',
      bindtap:'golooksousuo'
    },
    {
      title: '商铺管理',
      name: 'Shop',
      color: 'brown',
      icon: 'tagfill',
      bindtap:'goshop'
    },
    {
      title: '用户',
      name: 'User',
      color: 'red',
      icon: 'loading2',
      bindtap:'gouser'
    },
    {
      title: '待开发',
      name: 'loading',
      color: 'orange',
      icon: 'loading2',
      bindtap:''
    },
    {
      title: '待开发',
      name: 'loading',
      color: 'olive',
      icon: 'loading2',
      bindtap:''
    },
    {
      title: '待开发',
      name: 'loading',
      color: 'green',
      icon: 'loading2',
      bindtap:''
    },
  ],
  myimage:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this
    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: loginres => {
        console.log('[云函数] [login] user openid: ', loginres.result.openid)
        app.globalData.openid = loginres.result.openid
        self.setData({
          openid: loginres.result.openid
        })
        if (loginres.result.openid == 'ooqHY5ZrpVu_KH6v2Ml7KlGlT-no' || loginres.result.openid == 'ooqHY5VPsNzi80qnH0-RNU0S0lBA11' || loginres.result.openid == 'ooqHY5arIyp2vyz0PkM5NxBmFu-8') {
          self.setData({
            openid: loginres.result.openid
          })
        } else {
          db.collection('worker').where({
            _openid: loginres.result.openid
          }).get().then(res => {
            console.log(res.data)
            if (res.data.length > 0) {
              console.log(res.data[0])
              self.setData({
                worker: res.data[0]
              })
            }
          })
        }

      },
      fail: err => {
        console.error('[云函数] [login] 调用失败', err)
      }
    })
  },

  goyingye(e) {
    wx.navigateTo({
      url: 'yingye/yingye',
    })
  },
  gopeople(e) {
    wx.navigateTo({
      url: 'people/people',
    })
  },
  goshop(e) {
    wx.navigateTo({
      url: 'shop/shop',
    })
  },
  gogoods(e) {
    wx.navigateTo({
      url: 'goods/goods',
    })
  },
  golookdindan(e){
    wx.navigateTo({
      url: 'lookdindan/lookdindan',
    })
  },
  golookpintaidindan(e){
    wx.navigateTo({
      url: 'lookpintaidindan/lookpintaidindan',
    })
  },
  golooksousuo(e){
    wx.navigateTo({
      url: 'looksousuo/looksousuo',
    })
  },
  gouser(e) {
    wx.navigateTo({
      url: 'usershop/usershop',
    }) 
    /* var shop_id = 'info_10'
    wx.navigateTo({
      url: '../../user/shangpu/shangpu?shop_id=' + shop_id,
    }) */
  }
})